#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

#define lld long long
const lld MOD = 1e9 + 7;
const int MAXN = 109;

int n;
lld k;

// 定义矩阵类型别名
using Mat = lld[110][110];

void mat_mult(Mat &a, Mat &b, Mat &res) {
  lld tmp[MAXN][MAXN] = {0};

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k_ = 1; k_ <= n; ++k_) {
        tmp[i][j] = (tmp[i][j] + a[i][k_] * b[k_][j]) % MOD;
      }
    }
  }

  // 将结果复制到 res 中
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      res[i][j] = tmp[i][j];
}

void mat_pow(Mat &a, Mat &res) {
  // 初始化 res 为单位矩阵
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      res[i][j] = (i == j ? 1 : 0);

  Mat base, tmp_res;

  // 将 a 复制到 base
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      base[i][j] = a[i][j];

  while (k > 0) {
    if (k & 1) {
      mat_mult(res, base, tmp_res);
      for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
          res[i][j] = tmp_res[i][j];
    }
    mat_mult(base, base, tmp_res);
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        base[i][j] = tmp_res[i][j];
    k >>= 1;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  cin >> n >> k;

  Mat a, result;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      cin >> a[i][j];

  mat_pow(a, result);

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cout << result[i][j] << " ";
    }
    cout << "\n";
  }

  return 0;
}